﻿#region Using directives

using System;
using System.IO;

#endregion

namespace Weazel.Gezel.Simulator.Reference
{
  /// <summary>
  /// This exception is thrown when the file specified by
  /// an ipblock, which reads in files, is not found. See
  /// RomBlock and IjvmBlock.
  /// </summary>
  public class IpBlockFileNotFoundException : ApplicationException
  {
    private readonly string filename;
    /// <summary>
    /// Full name of the file which could not be found.
    /// </summary>
    /// <value></value>
    public string Filename
    {
      get { return filename; }
    }

    /// <summary>
    /// The ipblock which caused the exception to be thrown.
    /// </summary>
    private readonly AbstractIpBlock ipblock;
    public AbstractIpBlock IpBlock
    {
      get { return ipblock; }
    }

    public override string Message
    {
      get 
      {
        return string.Format("The ipblock '{0}' cannot find the file '{1}'", ipblock.Name, filename);
      }
    }

    /// <summary>
    /// Creates a new <see cref="IpBlockFileNotFoundException"/> instance.
    /// </summary>
    /// <param name="fileException">The underlying FileNotFoundException</param>
    /// <param name="ipblock">The ipblock which use the file</param>
    public IpBlockFileNotFoundException(FileNotFoundException fileException, AbstractIpBlock ipblock)
    {
      this.filename = fileException.FileName;
      this.ipblock = ipblock;
    }
  }
}
